import { defineStore } from 'pinia'
import { ref } from 'vue'
import { GetSetting,GetCitys } from '@/api/common'
export const useCommonStore = defineStore('common', () => {
  /** 默认城市 */
  const defaultCity = ref<RegionDetails>({id:1863,name:'北京'})
  /** 站点配置 */
  const setting = ref<Setting>()
  /** * 城市列表 */
  const citys = ref<any>()
  /**
   * 获取配置
   */
  if(!setting.value?.fileDomain) {
    GetSetting().then((res:ResponseData<Setting>) => {
      if (res.success) {
        setting.value = res.data
      }
    })
  }
  /**
   * 获取城市列表
   */
  if(!citys.value?.length) {
    GetCitys().then((res:ResponseData<RegionDetails[]>) => {
      if (res.success) {
        citys.value = res.data
      }
    })
  }
  
  return { defaultCity, setting, citys }
})